package com.bdth.bdthiss.controller;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.bdth.bdthiss.entity.Brand;
import com.bdth.bdthiss.service.BrandService;
import com.bdth.bdthiss.vo.PageVo;
import com.bdth.bdthiss.vo.Pagination;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2020/4/9.
 */
@Controller
@RequestMapping("/brand")
public class BrandController extends BaseController {
    @Autowired
    private BrandService brandService;

    @RequestMapping("index")
    public String index(){
        return "/brand/index";
    }

    @RequestMapping("search")
    public String search(){
        return "/brand/search";
    }

    @RequestMapping(value = "list")
    @ResponseBody
    public PageVo<Brand> getPageList(HttpServletRequest request, Pagination pagination,
                                     @RequestParam(required = false) String name){
        Map<String ,Object> query = new HashMap<>();
        //查询条件
        if(name!=null && !name.equals(""))
            query.put("name",name);
        Page<Brand> items = brandService.listPages(pagination, query);
        PageVo<Brand> pageVo = new PageVo<>(items.getRecords(),items.getTotal());
        return pageVo;
    }
}
